﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Tradex.Trading {

    /// <summary>
    /// This enumeration defines the possible stati that an order can have. They consolidate the various order states
    /// from within the system to the backend of the exchange.
    /// </summary>
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1028")]
    public enum OrderStatus : byte {

        // Here on: Initial state - this is a new order, not known in the system. This should never happen, as the status
        // is only used in the OrderStatus update we get, and then the order has been submitted.

        /// <summary>
        /// The order is new, and not submitted to the market as such.
        /// </summary>
        New,

        // Here on: Active order states. The order is in the system, is active.

        /// <summary>
        /// The order is submitted to the system.
        /// </summary>
        Submitted,

        /// <summary>
        ///  The order is entered into the system. It is active waiting to be filled. If the order has a trigger,
        ///  then the trigger was not yet triggered.
        /// </summary>
        Active,

        /// <summary>
        /// The order is waiting for trigger.
        /// </summary>
        Waiting,

        // Here On. Terminal states. The order has been completely processed, no more new events will
        // happen, with possibly the exception of busts / disputes.

        /// <summary>
        /// The order has been finished and filled (completely).
        /// </summary>
        CompleteFill,

        /// <summary>
        /// The order has been cancelled before any part of it was filled.
        /// </summary>
        CompleteCancel,

        /// <summary>
        /// The order has been rejected by the infrastructure or the exchange. This can have many reasons
        /// (bad time, not enough margin/collateral, bad instrument etc.)
        /// </summary>
        CompleteReject,

        /// <summary>
        /// There was a failure and the order was terminated.
        /// </summary>
        CompleteFailure,

        /// <summary>
        /// The order was completed but the state is unknown. This is most likely a missing status or something.
        /// FIll information as provided by the execution updates is valid, though.
        /// </summary>
        CompleteUnknown,

        /// <summary>
        /// The order was cancelled but had been partially filled before that. The fills naturally are valid - the
        /// not filled part was cancelled and is not not active anymore.
        /// </summary>
        CompletePartialFill,

        // Here on: Error states - basically unexpected and should not happen. The infrastructure falls back to that
        // if it does not recognize or have a prpeared map for an interim state. Unknown TERMINAL state is CancelUnknown.

        /// <summary>
        /// The order status is interim active (not terminal) but the subcode could not be determined.
        /// </summary>
        Unknown

    }
}
